package com.cat.flyweight;

import java.util.HashMap;

/**
 * @author cat
 * @version 2025/5/24 18:48
 * @description 工厂类(将该类设置为单例)
 * @since JDK17
 */

public class BeanFactory {
    private HashMap<String, AbstractBox> hashMap;

    // 在构造方法中进行初始化操作

    private BeanFactory() {
        this.hashMap = new HashMap<String, AbstractBox>();
        hashMap.put("I", new IBox());
        hashMap.put("L", new LBox());
        hashMap.put("O", new OBox());
    }

    // 根据名称获取图形对像
    public AbstractBox getShape(String name) {
        return hashMap.get(name);
    }

    private static BeanFactory beanFactory = new BeanFactory();

    public static BeanFactory getInstance() {
        return beanFactory;
    }
}
